import {ref,computed,onUnmounted} from 'vue'
import dayjs from 'dayjs'

export const usefomatTime = ()=>{
    let time = ref(0)
    let timer = null
    let fomDateTime = computed(()=>{
        // 转换为mm分ss秒格式
        return dayjs.unix(time.value).format('mm分:ss秒')
    })
    const start = (currtTime)=>{
        time.value = currtTime
        timer = setInterval(() => {
            time.value--
        }, 1000);
        if(time.value === 0) {
            clearInterval(timer)
        }
    }


    onUnmounted(()=>{
        clearInterval(timer)
    })
    return {
        fomDateTime,
        start
    }
}